<?php
include('action.abs.php');
class taxrate_mod extends action {
	function taxrate_mod() {
		parent :: action();
	}

   /*
    * 添加
    */
	function add() {
		$id = intval(V('g:id'));
		$rs = DR('taxrateCom.getTaxrateById', '', $id);	//获取数据
		if ($this->_isPost()) {
			$id = intval(V('p:id'));
			$name = trim(V('p:name'));
			$rate = trim(V('p:rate'));
			$remark = trim(V('p:remark'));
			if (empty($name)||empty($rate)) {
				$this->_error('类型和价格不能为空', array('add'));
			}
									
			$data = array(
							'name' => $name,
							'rate' => $rate,
							'remark' => $remark
						);
			$rs = DR('taxrateCom.saveTaxrateById', '', $data,$id);
			if ($rs['rst']) {
				$this->_succ('操作已成功', array('search'));
			}
			$this->_error('添加失败', array('add'));
		}
		TPL :: assign('info', $rs['rst']);
		TPL :: display('mgr/taxrate_add', '', 0, false);

	}

	/*
    * 搜索
    */
	function search() {
		$name = urldecode(V('r:keyword', ''));
		$page = (int)V('g:page', 1);
		$each = (int)V('g:each', 15);
		$offset = ($page -1) * $each;
		$num = ($page -1) * $each;

		$rss = $rs = "";
		$rss = DR('taxrateCom.getTaxrateByName', '', $name, $offset, $each);

        foreach($rss['rst'] as $value) {
            $rs[$value['id']] = $value;
        }
        $count = count($rss['rst']);

		$pager = APP :: N('pager');
		$page_param = array('currentPage'=> $page, 'pageSize' => $each, 'recordCount' => $count, 'linkNumber' => 10);
		$pager->setParam($page_param);

		TPL :: assign('num', $num);
		TPL :: assign('pager', $pager->makePageForKeyWord('',array('keyword'=>urlencode($name))));
		TPL :: assign('count', $count);
		TPL :: assign('name', $name);
        TPL :: assign('list', $rs); 
        TPL :: display('mgr/taxrate_list', '', 0, false);
	}


	/*
     * 删除
     */
	function del() {
		$id = V('g:id', 0);
		if (!$id) {
			$this->_error('用户id不能为空', array('search'));
		}
		
		$p = DR('adminCom.getAdminById', '', $this->_getUid());	//获取当前操作者的数据
		if(!$p['rst']['isroot']) {
			$this->_error('您无权限删除', array('search'));
		}

		$rs = DR('taxrateCom.delTaxrate', '', $id);
		if ($rs['rst']) {
			$this->_succ('操作已成功', array('search'));
		}
		
		$this->_error('删除失败',  array('search'));
	}
}
